package com.lab.webSocket.controller;

import com.lab.webSocket.dto.JsonMsgDto;
import com.lab.webSocket.service.AddUserService;
import com.lab.webSocket.service.ChatService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigInteger;

/**
 * Created by xu_jiaHui on 2017/9/7.
 */
@Controller
@RequestMapping("/ws_addUser")
public class AddUserController {
    @Resource
    private AddUserService addUserService;

    @Resource
    private ChatService chatService;

    @ResponseBody
    @RequestMapping("/addFriend")
    public JsonMsgDto addFriendByUserAccount(String friendAccount, String userAccount) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setSuccess(true);
            jsonMsgDto.setJsonData(addUserService.addFriendByUserAccount(friendAccount, userAccount));
        } catch (Exception e) {
            jsonMsgDto.setSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/findFriends")
    public JsonMsgDto findFriendsByInfo(String info) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setSuccess(true);
            jsonMsgDto.setJsonData(addUserService.findFriendsByInfo(info));
        } catch (Exception e) {
            jsonMsgDto.setSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
